﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class administrator_DangNhap : System.Web.UI.Page
{
    dulieuDataContext db=new dulieuDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int count = (from o in db.Users where o.UserName == txtusername.Text && o.Pass == pasword.Text select o).Count();
        if (count!=0)
        {
            int countAdmin = (from o in db.Users where o.UserName == txtusername.Text && o.Pass == pasword.Text && o.ID == 1 select o).Count();
            if (countAdmin != 0)
            {
                var admin = new HttpCookie("Admin", txtusername.Text) { Expires = DateTime.Now.AddHours(5) };
                Response.Cookies.Add(admin);
            }
            var username = new HttpCookie("username", txtusername.Text) {Expires = DateTime.Now.AddHours(5)};
            Response.Cookies.Add(username);
            Response.Redirect("default.aspx");
        }
        else
        {
            Response.Write("<SCRIPT language='JavaScript'>alert('Đăng nhập thất bại! Kiểm tra lại tên đăng nhập hoặc mật khẩu!');</SCRIPT> ");
        }
    }
}